package com.xxx.modules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xxx.modules.entity.Email;
import com.xxx.modules.entity.Exam;
import com.xxx.modules.mapper.EmailMapper;
import com.xxx.modules.service.EmailService;
import com.xxx.modules.utils.TimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@Service
public class EmailServiceImpl extends ServiceImpl<EmailMapper, Email> implements EmailService {

    @Resource
    private EmailMapper emailMapper;

    @Override
    public PageInfo<Email> selectEmailInfo(Email email, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper<Email> wrapper = new QueryWrapper<>();
        if (email.getAddressee() !=null){
            wrapper.like("addressee",email.getAddressee());
        }
        if (email.getSubject() !=null){
            wrapper.eq("subject",email.getSubject());
        }
        List<Email> data = emailMapper.selectList(wrapper);
        return new PageInfo<>(data);
    }

    @Override
    public void saveEmailInfo(Email email) {
        emailMapper.insert(email);
    }

    @Override
    public void updateEmailInfo(Email email) {
        emailMapper.updateById(email);
    }

    @Override
    public void delEmailInfo(Integer id) {
        emailMapper.deleteById(id);
    }

    @Override
    public void delBatchEmailInfo(String idList) {
        List<String> list = Arrays.asList(idList.split(","));
        emailMapper.deleteBatchIds(list);
    }
}
